# This sample code uses the Appium python client v2
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
import time
# For W3C actions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput

caps = {}
caps["platformName"] = "Android"
caps["appium:platformVersion"] = "7.1.2"
caps["appium:deviceName"] = "a4beb420"
caps["appium:appPackage"] = "com.bingbing.pet"
caps["appium:appActivity"] = ".activity.SplashActivity"
caps["appium:ensureWebviewsHavePages"] = True
caps["appium:nativeWebScreenshot"] = True
caps["appium:newCommandTimeout"] = 3600
caps["appium:connectHardwareKeyboard"] = True

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
time.sleep(2)
el1 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/llBottomTabTabMiddle")
el1.click()
time.sleep(2)
el2 = driver.find_element(by=AppiumBy.XPATH, value="/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.TextView[1]")
el2.click()
time.sleep(2)
el3 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/iv_record")
 
# 定位需要长按的元素

# 使用Ww3c长按该元素
actions = ActionChains(driver)
# 使用click_and_hold方法按住元素并保持
actions.w3c_actions.pointer_action.click_and_hold(el3)
# 使用pause方法指定按住的停顿时间2s
actions.w3c_actions.pointer_action.pause(5)
# 使用release方法松开鼠标
actions.w3c_actions.pointer_action.release()
# 最后使用perform方法执行以上操作。
actions.perform()
time.sleep(2)
el4 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/btn_send")
el4.click()
time.sleep(2)
el5 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/et_content")
el5.send_keys("你好")
time.sleep(2)
el6 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/btn_send")
el6.click()
time.sleep(3)
el11 = driver.find_element(by=AppiumBy.ID, value="com.bingbing.pet:id/llBottomTabTab1")
el11.click()
time.sleep(8)
# driver.quit()